package cn.yusei.teamTribe.dao.post;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import cn.yusei.teamTribe.dao.post.po.PostTagPO;

@Mapper
public interface PostTagDAO {

	final String POST_TAG_TABLE = " r_post_tag ";
	final String INSERT_FIELDS = " (post_id, tag_id) ";
	
	@Insert({"insert into", POST_TAG_TABLE, INSERT_FIELDS, "values(#{postId}, #{tagId})"})
	public void insert(PostTagPO postTagPO);
	
	@Delete({"delete from", POST_TAG_TABLE, "where post_id = #{postId} and tag_id = #{tagId}"})
	public void delete(PostTagPO postTagPO);
	
	@Select({"select exists (select * from", POST_TAG_TABLE, "where post_id = #{postId} and tag_id = #{tagId} limit 1)"})
	public boolean exists(PostTagPO postTagPO);
	
	@Select({"select tag_id from", POST_TAG_TABLE, "where post_id = #{id}"})
	public int[] selectTagById(@Param("id") int id);
	
	@Select({"select post_id from",POST_TAG_TABLE,"where tag_id = #{id}"})
	public int[] selectPostById(@Param("id")int id);
	
}
